import Taro from "@tarojs/taro";
import { RoleType } from "types/user";



// ?专家列表

export type ExpertProps = {
    address: string
    appoint_time: string
    backgroudimg: string
    company: string
    create_time: string
    def_address: string
    goodat: string
    headimg: string
    beans: number // ?帮豆
    points: number //积分
    id: number
    user_id: number
    name: string
    openid: string
    phone: string
    refer_code: string
    reg_code: string
    reg_name: string
    role: RoleType
    status: 1 | 0
    tags: string
    update_time: string
    description: string
    info: string
    partin_id: number // ?预约ID
    partin: boolean // ?是否预约过
    partin_status: 0 | 1 | 2 // ?0=待预约，1=已预约，2=已作废
    partin_time: number //剩余时间
}
export function ExpertList(params?: {
    name?: string
}) {
    return Taro.request({
        url: `/api/expert/list`,
        method: 'GET',
        data: params
    }).then<ExpertProps[]>(res => res?.data)
}


// ?专家详情
export function ExpertDetail(params: {
    expertId: number | string
}) {
    return Taro.request({
        url: `/api/expert/detail`,
        method: 'GET',
        data: params
    }).then<ExpertProps>(res => res?.data)
}


// ?专家视频
export type ExpertVideoProps = {
    create_time: string
    id: number
    priority: number
    title: string
    user_id: number
    video: string
    url: string
    log: {
        expert_id: number
        id: number
        status: 0 | 1 | 2
        time: string
        update_time: string
        user_id: number
        video_id: number
    }
}
export function ExpertVideos(params: {
    expertId: number | string
}) {
    return Taro.request({
        url: `/api/expert/videos`,
        method: 'GET',
        data: params
    }).then<ExpertVideoProps[]>(res => res?.data)
}


// ?学习视频
export function ExpertLearnVideo(params: {
    videoId: number
    status: 0 | 1 | 2 // ?学习状态 0=未学习，1=学习中，2=学习完
    time?: string
}) {
    return Taro.request({
        url: `/api/expert/learnVideo`,
        method: 'GET',
        data: params
    }).then(res => res?.data)
}



// ?获取专家可预约的时间
export type ExpertAppointmentTimesProps = {
    week: string
    date: string
    list: {
        address: string
        address_id: number
        am_date: string
        create_time: string
        end_time: string
        id: number
        start_time: string
        status: 0 | 1
        user_id: number
        appoint_time: string
    }[]
}
export function ExpertAppointmentTimes(params: {
    expertId: number | string
}) {
    return Taro.request({
        url: `/api/expert/appointmentTimes`,
        method: 'POST',
        data: params
    }).then<ExpertAppointmentTimesProps[]>(res => res?.data)
}

// ?预约专家
export function ExpertAppointment(params: {
    expertId: number | string
    times: string
    remark?: string
    sceneId?: string //场景ID
}) {
    return Taro.request({
        url: `/api/expert/appointment`,
        method: 'POST',
        data: params
    }).then(res => res?.data)
}




// ?场景列表
export type ExpertSceneProps = {
    code: string
    beans: number
    start_time: string
    start_date: string
    end_date: string
    end_hour: number
    end_time: string
    create_time: string
    description: string
    experts: ExpertProps[]
    id: number
    img: string
    info: string
    title: string
    sub_title: string
    priority: number
    points: number
    address: string
    is_professional: 1 | 0
    appoint_time: string
    order_status: 0 | 2 | 1 | 3  // ?0=待确认  1=已确认  3=已完成 2=已取消
    partin_time: number
    order_id: number
}
export function ExpertSceneList() {
    return Taro.request({
        url: `/api/expert/sceneList`,
        method: 'POST',
    }).then<ExpertSceneProps[]>(res => res?.data)
}

// ?场景详情
export function ExpertAppointScene(params: {
    sceneId: number,
    expertId: number
}) {
    return Taro.request({
        url: `/api/expert/appointScene`,
        method: 'POST',
        data: params
    }).then<ExpertSceneProps>(res => res?.data)
}


// ?场景详情
export function ExpertSceneDetail(params: {
    sceneId: string | number
}) {
    return Taro.request({
        url: `/api/expert/sceneDetail`,
        method: 'POST',
        data: params
    }).then<ExpertSceneProps>(res => res?.data)
}


// ?地址管理
export type ExpertAddressprops = {
    address: string
    area: string
    code: string
    create_time: string
    id: number
    is_hide: 0 | 1
    user_id: number | undefined | null
    def: boolean
    Z
}




export function ExpertAddress() {
    return Taro.request({
        url: `/api/expert/address`,
        method: 'POST',
    }).then<ExpertAddressprops[]>(res => res?.data)
}

// ?设置默认地址
export function ExpertDefAddress(params: {
    id: number
}) {
    return Taro.request({
        url: `/api/expert/defAddress`,
        method: 'POST',
        data: params
    }).then(res => res?.data)
}


// ?地址添加
export function ExpertAddAddress(params: {
    id?: number
    area: string
    code: string
    address: string
    def?: 1 | 0 // ?1:默认地址
}) {
    return Taro.request({
        url: `/api/expert/addAddress`,
        method: 'POST',
        data: params
    }).then(res => res?.data)
}

// ?地址删除
export function ExpertDelAddress(params: { id: number | string }) {
    return Taro.request({
        url: `/api/expert/delAddress`,
        method: 'DELETE',
        data: params
    }).then(res => res?.data)
}


// ?查询日期下可约时 + 已预约间段
export type ExpertTimesProps = {
    address_id: number
    am_date: string
    create_time: string
    end_time: string
    id: number
    start_time: string
    status: 0 | 1 | 2 // ? 0:不可预约 1:待预约 2:已预约
    user_id: number
    order_id: number
}
export function ExpertTimes(params: {
    date: string
}) {
    return Taro.request({
        url: `/api/expert/times`,
        method: 'POST',
        data: params
    }).then<ExpertTimesProps[]>(res => res?.data)
}


// ?查询日期下所有时间段，自动初始化
export function ExpertUpdateTimes(params: {
    date: string
}) {
    return Taro.request({
        url: `/api/expert/updateTimes`,
        method: 'POST',
        data: params
    }).then<ExpertTimesProps[]>(res => res?.data)
}

// ?设置帮豆
export function ExpertSetBeans(params: {
    beans: number
}) {
    return Taro.request({
        url: `/api/expert/setBeans`,
        method: 'POST',
        data: params
    }).then(res => res?.data)
}

// ?删除预约时间
export function ExpertDelTime(params: {
    id: number
}) {
    return Taro.request({
        url: `/api/expert/delTime`,
        method: 'DELETE',
        data: params
    }).then(res => res?.data)
}

// ?添加预约时间
export function ExpertAddTime(params: {
    date: string
    start_time: string
    end_time: string
}) {
    return Taro.request({
        url: `/api/expert/addTime`,
        method: 'DELETE',
        data: params
    }).then(res => res?.data)
}


// ?保存时间修改
export default function ExpertSaveTimes(params: {
    date: string
    data: string
    address: number
}) {
    return Taro.request({
        url: `/api/expert/saveTimes`,
        method: 'POST',
        data: params
    }).then(res => res?.data)
}

// ?定制咨询订单
export function OrderDiyList() {
    return Taro.request({
        url: `/api/order/diyList`,
        method: 'GET',
    }).then<{
        address: string
        beans: number
        begin_date: string
        begin_time: string
        create_time: string
        expert_id: number
        expert_name: string
        id: number
        no: string
        remark: string
        status: 0 | 1 | 2 | 3 | 4 | 5 //0=待审核，1=待支付，2=审核驳回，3=已支付，4=定制成功，5=定制失败
        user_id: number
    }[]>(res => res?.data)
}


// ?支付定制化咨询
export function OrderPayDiy(params: {
    id: number
}) {
    return Taro.request({
        url: `/api/order/payDiy`,
        method: 'POST',
        data: params
    }).then(res => res?.data)
}

// ?查询某个预约时段的详情
export function ExpertTimeDetail(params: {
    id: number | string
}) {
    return Taro.request({
        url: `/api/expert/timeDetail`,
        method: 'GET',
        data: params
    }).then(res => res?.data)
}

// ?预约咨询订单

export type ExpertAppointmentProps = {
    beans: number
    cancel_user: number
    code: string
    create_time: string
    expert_id: number
    id: number
    name: string
    company: string
    points: number
    remark: string
    scene_id: number
    star: number
    status: 0 | 1 | 2 | 3 // ? 0=待预约 1=已预约 2=已作废 3=已完成
    success_time: number
    times: string
    user_id: number
    suggest: string
}
export function ExpertAppointmentList() {
    return Taro.request({
        url: `/api/expert/appointmentList`,
        method: 'GET',
    }).then<ExpertAppointmentProps[]>(res => res?.data)
}


// ?专家建议
export function ExpertRecommend(params: {
    id: number
    msg: string
}) {
    return Taro.request({
        url: `/api/expert/recommend`,
        method: 'POST',
        data: params
    }).then(res => res?.data)
}

// ?专家评价

export function ExpertEvaluate(params: {
    expertId: string
}) {
    return Taro.request({
        url: `/api/expert/evaluate`,
        method: 'POST',
        data: params
    }).then<{
        create_time: string
        id: number
        msg: string
        name: string
        priority: number
        user_id: number
    }[]>(res => res?.data)
}


// ?查询当月有预约时段的日期
export function ExpertMonth() {
    return Taro.request({
        url: `/api/expert/month`,
        method: 'POST',
    }).then<string[]>(res => res?.data)
}